package scalapackage

import _root_.scala.collection.mutable.ArrayBuffer

/**
  * Created by Germmy on 2018/3/20.
  */
object SingletonObject {


  def main(args: Array[String]) {

    println(SessionFactory.getSessions)


    println(SessionFactory.getSessions.size)

    println(SessionFactory.getSessions(0))

    println(SessionFactory.removeSession)


  }


}

object SessionFactory {


  println("SessionFactory 被执行了")

  var i = 5


  val sessions = new ArrayBuffer[Session]()

  while (i > 0) {

    sessions += new Session //不确定这样写行不行

    i -= 1

  }


  def getSessions: ArrayBuffer[Session] = sessions


  def getSessionsNew = sessions //简写也要写=


  def addSession: Unit = {
    sessions += new Session
  }


  def removeSession: Unit = {
    sessions.remove(0)
  }

}

class Session {

}
